package com.sanjiahantang.youjiarole.module.article.presenters;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.sanjiahantang.uilibrary.adapter.listview.BaseAdapterHelper;
import com.sanjiahantang.uilibrary.adapter.listview.QuickAdapter;
import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseMvpPresenter;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.base.CallBack;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.module.article.beans.ArticleTypeListResponseBean;
import com.sanjiahantang.youjiarole.module.article.models.IArticleModel;
import com.sanjiahantang.youjiarole.module.article.models.impl.ArticleModel;
import com.sanjiahantang.youjiarole.module.article.views.ArticleView;
import com.sanjiahantang.youjiarole.module.article.views.impl.ArticleListActivity;
import com.sanjiahantang.youjiarole.module.common.beans.HelpBean;
import com.sanjiahantang.youjiarole.module.common.views.impl.WebActivity;
import com.sanjiahantang.youjiarole.utils.RelativeDateFormat;
import com.squareup.picasso.Picasso;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by zy on 2017/10/30.
 */

public class ArticlePresenter extends BaseMvpPresenter<ArticleView> {

    private IArticleModel articleModel;


    public ArticlePresenter(){
        articleModel = new ArticleModel();
    }

    public void searchArTrainInfoType(Context context,Map<String,Object> map , final BaseView.OnLoadListener onLoadListener,int type) {


        Map<String,Object> param = new HashMap<>();

        if (type == 1){//分类
            articleModel.searchArticleTypeRole(context,param, new CallBack<ArticleTypeListResponseBean>() {
                @Override
                public void onSuccess(ArticleTypeListResponseBean response, Context context, Object tag) {
                    hideProgress();
                    if (response.getCode() == RESPONSE_CODE_SUC){

                        onLoadListener.onLoad(response.getData());

                    }
                }

                @Override
                public void onFailure(String message) {
                    hideProgress();
                }
            });
        }else if (type == 2){
            param.put(KEY_PAGE,0);
            param.put(KEY_PAGE_SIZE,DEFAULT_PAGE_SIZE);
            param.put(KEY_PARAM,map);
            mView.showProgress();
            articleModel.searchArTrainInfoType(context,param, new CallBack<ArticleTypeListResponseBean>() {
                @Override
                public void onSuccess(ArticleTypeListResponseBean response, Context context, Object tag) {
                    hideProgress();
                    if (response.getCode() == RESPONSE_CODE_SUC){

                        onLoadListener.onLoad(response.getListData().getList());

                    }
                }

                @Override
                public void onFailure(String message) {
                    hideProgress();
                }
            });
        }else{
            hideProgress();
        }

    }

    public void searchArTrainInfoRole(Context context, String keyword, final BaseView.OnLoadListener onLoadListener){
        Map<String,Object> param = new HashMap<>();
        param.put(KEY_PAGE,0);
        param.put(KEY_PAGE_SIZE,DEFAULT_PAGE_SIZE);
        Map<String,Object> map = new HashMap<>();
        map.put(KEY_KEYWORDS,keyword);
        param.put(KEY_PARAM,map);
        articleModel.searchArTrainInfoRole(context,param, new CallBack<ArticleTypeListResponseBean>() {
            @Override
            public void onSuccess(ArticleTypeListResponseBean response, Context context, Object tag) {
                hideProgress();
                if (response.getCode() == RESPONSE_CODE_SUC){
                    onLoadListener.onLoad(response.getListData().getList());
                }
            }

            @Override
            public void onFailure(String message) {
                hideProgress();
            }
        });
    }

    private void hideProgress() {
        if (mView != null){
            mView.hideProgress();
        }
    }



}
